package com.atguigu.tingshu.user.rpc;

import com.atguigu.tingshu.common.result.Result;
import com.atguigu.tingshu.model.account.RechargeInfo;
import com.atguigu.tingshu.model.album.AlbumInfo;
import com.atguigu.tingshu.model.user.UserInfo;
import com.atguigu.tingshu.model.user.VipServiceConfig;
import com.atguigu.tingshu.user.service.UserInfoService;
import com.atguigu.tingshu.user.service.VipServiceConfigService;
import com.atguigu.tingshu.vo.user.UserInfoVo;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("/rpc/inner/userInfo")
public class UserInfoRpcController {
    @Autowired
    private UserInfoService userInfoService;

    @Autowired
    private VipServiceConfigService vipServiceConfigService;

    @GetMapping("/getUserInfo/{userId}")
    Result<UserInfoVo> getUserInfo(@PathVariable(value = "userId") Long userId){
        UserInfoVo userInfoVo = userInfoService.getUserInfo(userId);
        return Result.ok(userInfoVo);
    }
    @GetMapping("/getUserPaidAlbumTrack/{userId}/{albumId}")
    Result<Map<Long, String>> getUserPaidAlbumTrack(@PathVariable(value = "userId")Long userId,
                                                    @PathVariable(value = "albumId")Long albumId){

        Map<Long,String> map =  userInfoService.getUserPaidAlbumTrack(userId,albumId);
        return Result.ok(map);
    }

    @GetMapping("/getUserPaidAlbum/{userId}/{albumId}")
    Result<Boolean> getUserPaidAlbum(@PathVariable(value = "userId")Long userId, @PathVariable(value = "albumId") Long albumId){
        Boolean isPaidAlbum = userInfoService.getUserPaidAlbum(userId,albumId);
        return Result.ok(isPaidAlbum);
    }
    @GetMapping("/getUserPaidAlbum/{itemId}")
    Result<VipServiceConfig> getVipConfigById(@PathVariable(value = "itemId") Long itemId){
        VipServiceConfig vipServiceConfig = vipServiceConfigService.getById(itemId);
        return Result.ok(vipServiceConfig);
    }

    @GetMapping("/getUserIdByOpenId/{openid}")
    Result<String> getUserIdByOpenId(@PathVariable(value = "openId") String openId){
        LambdaQueryWrapper<UserInfo> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(UserInfo::getWxOpenId,openId);
        UserInfo userInfo = userInfoService.getOne(wrapper);
        return Result.ok(userInfo.getId().toString());
    }

    @GetMapping("/updateExpireVip")
    void updateExpireVip(){
        userInfoService.updateExpireVip();
    }


}
